package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysControlVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysControl;
import com.ruoyi.system.service.ISysControlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 控件Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/system/control")
public class SysControlController extends BaseController
{
    @Autowired
    private ISysControlService sysControlService;

    /**
     * 查询控件列表
     */
    @PreAuthorize("@ss.hasPermi('system:control:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysControl sysControl)
    {
        startPage();
        List<SysControl> list = sysControlService.selectSysControlList(sysControl);
        return getDataTable(list);
    }

    /**
     * 查询控件列表VO类
     */
    @GetMapping("/voList")
    public TableDataInfo voList(SysControl sysControl)
    {
        startPage();
        List<SysControlVO> list = sysControlService.selectSysControlVOList(sysControl);
        return getDataTable(list);
    }

    /**
     * 导出控件列表
     */
    @PreAuthorize("@ss.hasPermi('system:control:export')")
    @Log(title = "控件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysControl sysControl)
    {
        List<SysControl> list = sysControlService.selectSysControlList(sysControl);
        ExcelUtil<SysControl> util = new ExcelUtil<SysControl>(SysControl.class);
        util.exportExcel(response, list, "控件数据");
    }

    /**
     * 获取控件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:control:query')")
    @GetMapping(value = "/{controlId}")
    public AjaxResult getInfo(@PathVariable("controlId") Long controlId)
    {
        return success(sysControlService.selectSysControlByControlId(controlId));
    }

    /**
     * 新增控件
     */
    @PreAuthorize("@ss.hasPermi('system:control:add')")
    @Log(title = "控件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysControl sysControl)
    {
        return toAjax(sysControlService.insertSysControl(sysControl));
    }

    /**
     * 修改控件
     */
    @PreAuthorize("@ss.hasPermi('system:control:edit')")
    @Log(title = "控件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysControl sysControl)
    {
        return toAjax(sysControlService.updateSysControl(sysControl));
    }

    /**
     * 删除控件
     */
    @PreAuthorize("@ss.hasPermi('system:control:remove')")
    @Log(title = "控件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{controlIds}")
    public AjaxResult remove(@PathVariable Long[] controlIds)
    {
        return toAjax(sysControlService.deleteSysControlByControlIds(controlIds));
    }
}
